<template>
  <div class="history-report">
    <div v-if="historyList.length > 0" class="list-container">
      <div
        :class="{'is_active': item.is_active, 'is_current': currentId === item.id}"
        v-for="item in historyList"
        :key="item.key"
        @click="setCurrent(item)"
      >
        <div class="title">{{item.reportName}}</div>
        <div class="time">
          <div class="item-label">教师：{{item.creatorName}}</div>
          <div class="item-label">学生：{{item.studentName}}</div>
          <div class="item-label">生成时间：{{item.createTime}}</div>
        </div>
      </div>
    </div>
    <cus-empty v-else></cus-empty>
  </div>
</template>

<script lang="ts">
import { ref, toRef } from 'vue'
import { ElMessage } from 'element-plus'
export default {
  props: {
    list: {
      type: Array,
      default: () => {
        return []
      },
    },
    currentId: {
      type: String,
      default: '',
    },
  },
  setup(props) {
    let historyList = toRef(props, 'list')
    let currentSelect = ref({})
    const setCurrent = (data) => {
      currentSelect.value = data
      historyList.value.map(
        (i: any) => (i.is_active = i.id === data.id ? !data.is_active : false)
      )
    }
    setCurrent({ id: props.currentId })
    const save = (resolve, reject) => {
      if (historyList.value.every((e: any) => !e.is_active))
        return ElMessage.warning('请选择历史阶段报告！')
      resolve(currentSelect.value)
    }
    return { save, currentSelect, historyList, setCurrent }
  },
}
</script>

<style scoped lang="scss">
.history-report {
  > .list-container {
    > div {
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 10px;
      background: #ffffff;
      cursor: pointer;
      background: #eff2f5;
      border-radius: 6px;
      padding: 10px 20px;
      margin-bottom: 10px;
      .title {
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        margin-bottom: 8px;
      }
      .time {
        display: flex;
        .item-label {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #666666;
          margin-right: 20px;
        }
      }
    }
    .is_active {
      background: #fff;
      box-shadow: 0px 1px 8px 0px rgba(72, 72, 72, 0.2);
    }
    .is_current {
      position: relative;
      &::after {
        content: '当前';
        position: absolute;
        top: 10px;
        right: 10px;
        background: #e9f7f6;
        border-radius: 6px;
        border: 1px solid #72b22a;
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #72b22a;
        padding: 2px 14px;
      }
    }
  }
}
</style>
